package com.example.module_home.netalert

import android.net.ConnectivityManager
import android.net.NetworkRequest
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.WindowManager
import androidx.core.content.ContextCompat
import com.example.module_home.R
import kotlinx.android.synthetic.main.home_activity_net_alert.*

class NetAlertActivity : AppCompatActivity() {

    val TAG = NetAlertActivity::class.java.simpleName.toString()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.home_activity_net_alert)


        checkConnection()

        btn_check.setOnClickListener {
            checkConnection()
        }

    }


    private fun checkConnection() {

        val windowManager = ContextCompat.getSystemService(this, WindowManager::class.java)


        val connectivityManager =
            ContextCompat.getSystemService(this, ConnectivityManager::class.java)

        val networkRequest = NetworkRequest.Builder().build()

        //Log.e(TAG, "==${connectivityManager == null}")

        connectivityManager?.registerNetworkCallback(networkRequest, NetworkListenerImpl())

    }
}